<?php

namespace app\home\controller;
use app\home\model\pyg_cart;
use app\home\model\pyg_category;
use app\home\model\pyg_goods;
use app\Request;
use think\facade\Db;
use think\facade\Session;
use think\facade\View;

class Pay
{
    public function pay(Request $request)
    {
        return \think\facade\View::fetch('pay/pay');
    }
    public function getOrder()
    {
        $obj = new pyg_category();
        $res = $obj->showCategory()->toArray();
        $showCategory = get_tree_list($res);
        $reb = Db::table('pyg_address')->where('user_id',Session('id'))->select()->toArray();
        $id = Session('id');
        $obe = new pyg_cart();
        $data = $obe->with(['showCart','showCarts'])->where('user_id',$id)->select()->toArray();
        $sum = 0;
        $number = 0;
        foreach ($data as $key=>$val)
        {
            $data[$key]['sum']=$val['number']*$val['price'];
        }
        foreach ($data as $val)
        {
            $sum = $sum+=$val['sum'];
        }
        foreach ($data as $val)
        {
            $number = $number+=$val['number'];
        }
        return View::fetch('pay/getOrderInfo',['showCategory'=>$showCategory,'reb'=>$reb,'data'=>$data,'number'=>$number,'sum'=>$sum]);
    }
    public function address($id)
    {
        $date = "";
        $address = Db::table('pyg_address')->where('id',$id)->where('user_id',Session('id'))->select()->toArray();
        foreach ($address as $val)
        {
            $data = [
                  '寄送至：'=>$val['area'],
                  '收货人：'=>$val['consignee'],
                  '手机号：'=>$val['phone'],
            ];
        }
        return success($data);
    }
}